package edu.uct.tamnd.viettourism.places;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import edu.uct.tamnd.lazyloadimage.ImageLoader;
import edu.uct.tamnd.viettourism.R;

public class PlacesItemArrayAdapter extends ArrayAdapter<PlacesItem>{
	private Context context;
	private ViewHolder holder;
	private ImageLoader imageLoader;
	private ArrayList<PlacesItem> placesItems;
	
	public PlacesItemArrayAdapter(Context context, int textViewResourceId, ArrayList<PlacesItem> placesItems)
	{
		super(context, textViewResourceId, placesItems);
		this.context = context; 
		imageLoader = new ImageLoader(context);
		this.placesItems = placesItems;
		
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null){
			holder = new ViewHolder();
			LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = layoutInflater.inflate(R.layout.places_row_item, null);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.tvPlacesName = (TextView) convertView.findViewById(R.id.tvPlacesName);
		holder.tvPlacesName.setText(placesItems.get(position).getName());
		
		holder.tvPlacesDescription = (TextView) convertView.findViewById(R.id.tvPlacesDescription);
		holder.tvPlacesDescription.setText(placesItems.get(position).getDescription());
		
		holder.imvPlacesThumbnail = (ImageView) convertView.findViewById(R.id.imvPlacesThumbnail);
		imageLoader.DisplayImage(placesItems.get(position).getImage(), holder.imvPlacesThumbnail);
		
		return convertView;
	}
	
	private class ViewHolder{
		public ImageView imvPlacesThumbnail;
		public TextView tvPlacesDescription;
		public TextView tvPlacesName;
		
		
	}
}
